<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

		<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
		<style>
			.data_remark {
				border: 1px solid #eee;
				width: auto;
				height:30px;
				padding:5px;
			}
			.toolong{
				width: 100px;
			}
		</style>
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>游戏用户</a>
						</li>
						<li class="active">用户管理</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							用户列表
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
								<div class="row" style="margin-bottom:10px;">
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">用户id</button>
											</div>
											<input type="text" class="form-control" id="user_id">
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">注册ip</button>
											</div>
											<input type="text" class="form-control" id="register_ip">
										</div>
									</div>

									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">设备id</button>
											</div>
											<input type="text" class="form-control" id="device_id">
										</div>
									</div>
									<!-- <div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">手机号码</button>
											</div>
											<input type="text" class="form-control" id="phone">
										</div>
									</div> -->
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">注册时间</button>
											</div>
											<!-- /btn-group -->
											<input type="text" class="form-control" id="select_time" autocomplete="off">
											<div class="input-group-addon clearBtns" onclick="clearRangeTime(this)">x</div>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<button type="button" class="btn bg-primary margin" onclick="search()"><i class="fa fa-search" ></i>&nbsp;搜索</button>
										<button type="button" class="btn bg-primary margin" onclick="reset()"><i class="fa fa-trash" ></i>&nbsp;重置</button>
										<button type="button" class="btn bg-primary margin" onclick="batchBlack()"><i class="fa fa-trash" ></i>&nbsp;批量拉黑</button>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<th><input type="checkbox" name="allcheck" /></th>
												<th>用户id</th>
												<th>资产总额</th>
												<th>备注</th>
												<th>状态</th>
												<th>设备ID</th>
												<th>注册IP</th>
												<th>基础算力</th>
												<th>网络算力</th>
												<th>注册时间</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
					<div class="modal fade parents in" id="toBlackModal">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">	                  				<span aria-hidden="true">×</span>								</button>
									<h4 class="modal-title">添加黑名单</h4> </div>
								<div class="modal-body">
									<form class="form-horizontal">
										<div class="box-body">
											<input type="hidden" name="id" value="">
											<p>是否将“<span name="name"></span>”移入黑名单</p>
											<label class="margin-bottom-none col-xs-12" style="width:100%;font-weight:normal;padding-left: 0;">
												拉黑到期时间：
												<input type="text" class="form-control" id="end_time"/>
											</label>

											<label class="margin-bottom-none col-xs-12" style="width:100%;font-weight:normal;padding-left: 0;">
												操作密码：
												<input type="password" class="form-control" name="op_password">
											</label>
											<label class="margin-bottom-none col-xs-12" style="width:100%;font-weight:normal;padding-left: 0;">
												备注说明：
												<input type="text" class="form-control" name="remark">
											</label>
										</div>
									</form>
								</div>
								<div class="modal-footer"> <button type="button" class="btn btn-primary save" onclick="toBlackSave()">确定</button> </div>
							</div>
						</div>
					</div>
					<div class="modal fade parents in" id="balanceDetailsModal">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">	                  				<span aria-hidden="true">×</span>								</button>
									<h4 class="modal-title">账户详情</h4> </div>
								<div class="modal-body">
									<form class="form-horizontal">
										<div class="box-body">
											<input type="hidden" name="id" value="">
											<div class="input-group">
												<span class="input-group-addon">币种名称</span>
												<select name="chain_id" class="form-control"></select>
											</div>

										</div>
										<div class="box-body">
											<table id="example1" class="display nowrap table table-bordered table-striped" style="width:100%;">
												<thead>
													<tr>
														<th>币种名称</th>
														<th>币数量</th>
													</tr>
												</thead>
												<tbody></tbody>
											</table>
										</div>
									</form>
									<div style="height:20px;"> </div>
								</div>

							</div>
						</div>
					</div>
				</section>
			</div>
		</div>

		<div class="modal fade parents in" id="setSuperModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">	                  				<span aria-hidden="true">×</span>								</button>
						<h4 class="modal-title">设置超级会员</h4> </div>
					<div class="modal-body">
						<form class="form-horizontal">
							<div class="box-body">
								<input type="hidden" name="id" />
								<input type="hidden" name="isSuper" />
								<p>是否将“<span name="name"></span>”<span name="doSuper">设置为</span>超级会员</p>

							</div>
						</form>
					</div>
					<div class="modal-footer"> <button type="button" class="btn btn-primary save" onclick="setSuperSave()">确定</button> </div>
				</div>
			</div>
		</div>
		<div class="modal fade parents in" id="batchBlackModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">	                  				<span aria-hidden="true">×</span>								</button>
						<h4 class="modal-title">确定批量删除</h4> </div>
					<div class="modal-body">
						<form class="form-horizontal">
							操作密码
							<label class="margin-bottom-none col-xs-12" style="width:100%;font-weight:normal;padding-left: 0;">
												<input type="password" class="form-control" name="op_password" >
											</label>
						</form>
					</div>
					<div style="height:20px;"></div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="batchBlackSave()">确定</button>
					</div>
				</div>
			</div>
		</div>

		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>

		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		<script src="bower_components/moment/min/moment.min.js"></script>
		<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>

		<script src="dist/js/adminlte.min.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/buyu_fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script src="js/getList.js"></script>
		<script type="text/javascript">
			if(GetRequest().user_id) {
				$('#user_id').val(GetRequest().user_id)
			}

			$.ajax({
				"type": 'post',
				"url": url + "Back_MainChain",
				"contentType": "application/x-www-form-urlencoded",
				"headers": {
					"auth-token": localStorage.getItem("wallet_token")
				},
				'data': {
					data: JSON.stringify({
						page_num: 1
					})
				},
				'success': function(res) {
					if(res.status == 1000||res.status == 102) {
						ToLogin(res)
						return false;
					} else if(res.status != 1) {
						alert(res.error);
						return false;
					}
					$.each(res.data.data_list, function(index, item) {
						$("#balanceDetailsModal [name = chain_id]").append('<option value=' + item.id + '>' + item.name + '</option>')
					})
				}
			})

			$('#select_time').daterangepicker({
				timePicker: true,
				timePicker24Hour: true,
				autoUpdateInput: false,
				locale: {
					format: "YYYY-MM-DD HH:mm"
				}
			})
			$('#end_time').datepicker({
				autoclose: true,
				format: 'yyyy-mm-dd',
			})

			var table = $('#example').DataTable({
				'ordering': false,
				'lengthChange': false,
				'searching': false,
				'info': true,
				"processing": true,
				"serverSide": true,
				'scrollX': true,
				"ajax": {
					"type": 'post',
					"url": url + "Back_UserList",
					"contentType": "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"data": function(d) {
						$("[name = allcheck]").prop('checked', false);
						var dataType = {
							// phone: {
							// 	type: 'string',
							// 	value: $("#phone").val()
							// },
							device_id: {
								type: 'string',
								value: $("#device_id").val()
							},
							register_ip: {
								type: 'string',
								value: $("#register_ip").val()
							},
							user_id: {
								type: 'string',
								value: $("#user_id").val()
							},
							start_time: {
								type: 'time',
								value: $("#select_time").val().substring(0, 16)
							},
							end_time: {
								type: 'time',
								value: $("#select_time").val().substring(19, 35)
							}
						}
						var Json = renderData(dataType);
						Json.page_num = d.start / 10 + 1;
						var data = {};
						data.data = JSON.stringify(Json);
						return data;
					},
					"dataFilter": function(data) {
						var datajson = eval('(' + data + ')');
						if(datajson.status == 1000||datajson.status == 102) {
							ToLogin(datajson)
							return false;
						} else if(datajson.status != 1) {
							alert(datajson.error);
							return false;
						}
						var json = {};
						if(datajson.data == null) {
							json.recordsTotal = 0;
							json.recordsFiltered = 0;
							json.data = [];
							return JSON.stringify(json);
						} else {
							json.recordsTotal = datajson.data.total;
							json.recordsFiltered = datajson.data.total;
							json.data = datajson.data.data_list;
							return JSON.stringify(json);
						}
					}
				},
				"columns": [{
						data: null,
						render: function(data) {
							return '<input type="checkBox" name="userCheck" value="' + data.id + '">'
						} //'id'
					},
					{
						data: 'id'
					},
					{
						data: null,
						render: function(data) {
							return data.balance_sum + '<button class="btn btn-success button-margin" onclick="balanceDetails(' + data.id + ')">详情</button>'
						} //'balance_sum'
					},

					{
						data: null,
						render: function(data) {
							return '<input class="data_remark" value="' + data.remark + '" user_id ="'+data.id+'">';
						} //'register_time'
					},
					{

						data: null,
						render: function(data) {
							return userState(data.status)
						}
					},
					{
						data: null,
						render: function(data) {
							return "<div class='toolong dbClick' key = 'device_id'>" + data.device_id + "</div>"
						}
					},
					{
						data: null,
						render: function(data) {
							return "<div class='toolong dbClick' key = 'register_ip'>" + data.register_ip + "</div>"
						}
					},
					{
						data: 'basic_power'
					},
					{
						data: 'netword_power'
					},
					{
						data: 'register_time'
					},
					{
						data: null,
						render: function(data) {
							var blacklist = '<button type="button" class="btn bg-navy button-margin" onclick="toBlack(this)" id=""><i class="fa fa-warning"></i>&nbsp;&nbsp;拉黑</button>',
								unBlacklist = '<button type="button" class="btn btn-success button-margin" onclick="cancelBlack(this)"><i class="fa fa-recycle"></i>&nbsp;&nbsp;解除黑名单</button>',

								check = '<button type="button" class="btn btn-primary button-margin" onclick="checkDetails(' + data.id + ')" id=""><i class="fa fa-search"></i>&nbsp;查看详情</button>';

							//状态 1：正常  2：锁定（禁止游戏）   3：拉黑（禁止登录，游戏）   4：注销
							var str = "<input type='hidden' value='" + JSON.stringify(data) + "'>"; //+ check;
							if(data.status == 1) {
								str += blacklist;
							} else {
								str += unBlacklist;
							}
							return str;
						}
					}
				]
			})
		</script>
		<script type="text/javascript">
			function balanceDetails(id) {
				$('#balanceDetailsModal').modal('show');
				$('#balanceDetailsModal [name=id]').val(id)
				$.ajax({
					type: "post",
					url: url + "Back_UserCoinList",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({ //昵称
							user_id: id,
							chain_id: $("#balanceDetailsModal [name=chain_id]").val(),
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#example1 tbody").html('');
						$.each(res.data.coin_list,function(index,item){
							$("#example1 tbody").append('<tr><td>'+item.name+'</td><td>'+item.balance_show +"&nbsp;"+item.name+"&nbsp; ≈ &nbsp;&nbsp;￥&nbsp;"+item.change_balace +'</td></tr>')
						})
					}
				})
				
			}
			
			$("#balanceDetailsModal [name=chain_id]").change(function() {
				balanceDetails($('#balanceDetailsModal [name=id]').val())
			})
			// 拉黑
			function toBlackSave() {
				var parme = {
					end_time: $("#end_time").val() + " 00:00:00",
					details: $("#toBlackModal [name=id]").val(),
					type: 1,
					remark: $("#toBlackModal [name=remark]").val(),
					op_password: $("#toBlackModal [name=op_password]").val(),
				}
				$.ajax({
					"type": "post",
					"url": url + "Back_BlackAdd", // + $("#toBlackModal [name=id]").val(),
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify(parme)
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#toBlackModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function toBlack(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				$("#toBlackModal [name=id]").val(data.id);
				$("#toBlackModal [name=name]").html(data.account);
				$("#endTime").val("");
				$("#toBlackModal [name=OPassword]").val("");
				$("#toBlackModal").modal("show");

			}

			//移出黑名单
			function cancelBlackSave() {
				$.ajax({
					type: "post",
					url: url + "Back_BlackDel",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({ //昵称
							type: 1,
							details: $("#cancelBlackModal [name=id]").val(),
							op_password: $("#cancelBlackModal [name=OPassword]").val(),
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#cancelBlackModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function cancelBlack(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				var deleteJson = {
					name: "cancelBlack",
					title: "移除黑名单",
					needPassword: true,
					arg: {
						id: data.id,
						name: data.phone
					}
				};
				deleteModal(deleteJson, 'cancelBlackSave');
			}

			function checkDetails(id) {
				window.location.href = 'user_details.html?user_id=' + id;
			}

			$("#example").on("click", ".isSuperSet", function() {
				$("#setSuperModal").find("[name=name]").text($(this).attr("data_account"))
				$("#setSuperModal").find("[name=id]").val($(this).attr("data_id"))

				if($(this).hasClass("active")) {
					$("#setSuperModal").find("[name=doSuper]").text("取消")

					$("#setSuperModal").find("[name=isSuper]").val(0)
				} else {
					$("#setSuperModal").find("[name=doSuper]").text("设置为")
					$("#setSuperModal").find("[name=isSuper]").val(1)
				}
				$("#setSuperModal").modal("show");
			})

			function setSuperSave() {
				//				return false;
				//				if()
				$.ajax({
					type: "post",
					url: url + "Back_UpdateUserIsSuper",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({ //昵称
							user_id: $("#setSuperModal [name=id]").val(),
							is_super: $("#setSuperModal [name=isSuper]").val(),
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							move("error", res.error);
							return false;
						}
						$("#setSuperModal").modal("hide");
						$("#setSuperModal").find("[name=OPassword]").val("")
						move("success", "修改成功");
						table.draw(false);
					}
				})
			}

			function batchBlack() {
				if($("#example input[name=userCheck]:checked").length == 0) {
					move('error', '请勾选拉黑目标')
				} else {
					$("#batchBlackModal").modal('show');
				}
			}

			$("[name=allcheck]").change(function() {
				if($(this).prop('checked')) {
					$("#example [name=userCheck]").prop("checked", true)
				} else {
					$("#example [name=userCheck]").prop("checked", false)
				}
			})
			$("#example").on('change', '[name=userCheck]', function() {
				if($("[name=userCheck]").length == $("[name=userCheck]:checked").length) {
					$("[name=allcheck]").prop('checked', true);
				} else {
					$("[name=allcheck]").prop('checked', false);
				}
			})

			function batchBlackSave() {
				var date = new Date().getTime() / 1000;
				date += 630720000;
				time = timestampToTime(date)
				var length = $("#example input[name=userCheck]:checked").length,
					i = 0;
				$.each($("#example input[name=userCheck]:checked"), function(index, item) {
					var parme = {
						end_time: time + " 00:00:00",
						type: 1,
						remark: '异常批量拉黑',
						op_password: $("#batchBlackModal [name=op_password]").val(),
						details: $(item).val()
					}
					$.ajax({
						"type": "post",
						"url": url + "Back_BlackAdd", // + $("#toBlackModal [name=id]").val(),
						'contentType': "application/x-www-form-urlencoded",
						"headers": {
							"auth-token": localStorage.getItem("wallet_token")
						},
						data: {
							data: JSON.stringify(parme)
						},
						dataType: "json",
						success: function(res) {
							i++;
							if(res.status == 1000||res.status == 102) {
								ToLogin(res)
								return false;
							} else if(res.status != 1) {
								if(length == i) {
									alert(res.error)
								}
								return false;
							}
							if(length == i) {
								$("#batchBlackModal").modal("hide");
								table.draw(false);
							}
						}
					})
				})

			}
			$("#example").on('dblclick', ".dbClick", function() {
				$(".buyu_search_group input").val("");
				$(".buyu_search_group select option:first").prop("selected", "selected");
				var key = $(this).attr('key');
				$("#" + key).val($(this).html())
				table.ajax.reload();
			})

			$("#example").on('change', '.data_remark', function() {
				$.ajax({
					"type": "post",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"url": url + "Back_UpdateUserRemark", // + $("#toBlackModal [name=id]").val(),
					'contentType': "application/x-www-form-urlencoded",
					data: {
						data: JSON.stringify({
							user_id :$(this).attr('user_id'),
							remark :$(this).val(),
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error)
							return false;
						}
						move("success",'修改成功')
					}
				})
			})
		</script>
	</body>

</html>